﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PSE.Deployment.Engine.CustomExceptions
{
    public class MultipleException : Exception
    {
        public MultipleException(string message)
            : base(message)
        {
            this.InnerExceptions = new List<Exception>();
        }

        public MultipleException(string message, List<Exception> innerExceptions)
            : base(message)
        {
            if (innerExceptions == null)
	            throw new ArgumentNullException("innerExceptions");

            this.InnerExceptions = innerExceptions;
        }

        public List<Exception> InnerExceptions { get; private set; }

        public override string ToString()
        {
            StringBuilder exString = new StringBuilder(base.ToString());

            if (this.InnerExceptions.Count > 0)
            {
                exString.AppendLine();
                exString.Append("Inner Exceptions:");
            }

            foreach (Exception ex in this.InnerExceptions)
            {
                exString.AppendLine();
                exString.AppendLine("-----------------------------------------------------------------------------");
                exString.Append(ex.ToString());
            }

            return exString.ToString();
        }
    }
}
